package com.buss.core.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 用户机构信息
 * @author gykl
 *
 */
@Entity
@Table(name="core_organization")
@TableGenerator(name="organ_pk_sequence",initialValue=1,allocationSize=1,pkColumnName="seq_col",
		pkColumnValue="organ_seq",valueColumnName="seq_val",table="core_pk_sequence")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Organization implements Serializable{

	private static final long serialVersionUID = 6307752912395283946L;

	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator="organ_pk_sequence")
	private Long id;
	
	/**
	 * 单位编码
	 */
	@Column(length = 50,nullable=false)
	private String companyId;
	
	/**机构名称*/
	@Column(nullable=false,length = 50)
	private String name;
	
	/**机构电话*/
	private String telePhone;
	
	/**联系人*/
	@Column(length = 20)
	private String linkMan;
	
	/**上层机构编码*/
	@Column(nullable=false)
	private Long parentId;
	
	/**子菜单数量*/
	private Long nodeNum;
	
	/**是否有子节点*/
	@Transient
	private boolean hasNode;
	
	@Transient
	private Integer childLevel;
	
	/**子机构列表*/
	@Transient
	private List<Organization> nodes;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCompanyId() {
		return companyId;
	}

	public void setCompanyId(String companyId) {
		this.companyId = companyId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTelePhone() {
		return telePhone;
	}

	public void setTelePhone(String telePhone) {
		this.telePhone = telePhone;
	}

	public String getLinkMan() {
		return linkMan;
	}

	public void setLinkMan(String linkMan) {
		this.linkMan = linkMan;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public Long getNodeNum() {
		return nodeNum;
	}

	public void setNodeNum(Long nodeNum) {
		this.nodeNum = nodeNum;
	}

	public boolean isHasChild() {
		if(getNodeNum() != null && getNodeNum() > 0){
			return true;
		}else{
			return false;
		}
	}

	public void setHasNode(boolean hasNode) {
		this.hasNode = hasNode;
	}

	public Integer getChildLevel() {
		return childLevel;
	}

	public void setChildLevel(Integer childLevel) {
		this.childLevel = childLevel;
	}

	public List<Organization> getNodes() {
		return nodes;
	}

	public void setNodes(List<Organization> nodes) {
		this.nodes = nodes;
	}
	
	
}
